[id].vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <LayoutContainer>
  3. <UiLoadingPanel v-if="pending" />
  4. <div v-else>
  5. <h2>Editer la zone de résidence</h2>
  6. <UiForm
  7. ref="form"
  8. :model="ResidenceArea"
  9. :entity="residence_areas"
  10. :submitActions="submitActions"
  11. >
  12. <UiInputText
  13. field="label"
  14. v-model="residence_areas.label"
  15. :rules="rules()"
  16. />
  17. </UiForm>
  18. </div>
  19. </LayoutContainer>
  20. </template>
  21. <script setup lang="ts">
  22. import { ref } from 'vue'
  23. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  24. import ResidenceArea from '~/models/Billing/ResidenceArea'
  25. import { useRoute } from 'vue-router'
  26. import { useI18n } from 'vue-i18n'
  27. import { AnyJson } from '~/types/data'
  28. import { SUBMIT_TYPE } from '~/types/enum/enums'
  29. const i18n = useI18n()
  30. const { fetch } = useEntityFetch()
  31. const route = useRoute()
  32. const idValue = Array.isArray(route.params.id)
  33. ? route.params.id[0]
  34. : route.params.id
  35. const residenceID = ref(parseInt(idValue))
  36. const goBackRoute = { path: `/parameters`, query: { tab: 'residenceAreas' } }
  37. const submitActions = computed(() => {
  38. let actions: AnyJson = {}
  39. actions[SUBMIT_TYPE.SAVE_AND_BACK] = goBackRoute
  40. return actions
  41. })
  42. const { data: residence_areas, pending } = fetch(
  43. ResidenceArea,
  44. residenceID.value
  45. )
  46. const rules = () => [
  47. (label: string | null) =>
  48. (label !== null && label.length > 0) || i18n.t('please_enter_a_value'),
  49. ]
  50. </script>